<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>审核列表(供应商)</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript">

        //查看图书详情
        function showDetails(index) {
            $('#detail').dialog('open');
            let row = $("#booklist").datagrid("getData").rows[index];
            let detail = row.book;
            console.log(row)
            let number = row.number;
            let imgurl = detail.imgurl;
            if (imgurl.indexOf("http") === -1 && imgurl.indexOf("https") === -1) {
                imgurl = '/manager' + imgurl;
            }
            $("#bookname").textbox('setValue', detail.bookname);
            $("#ISBN").textbox('setValue', detail.iSBN);
            $("#price").textbox('setValue', detail.price);
            $("#number").textbox('setValue', number);
            $("#groupprice").textbox('setValue', detail.groupprice);
            $("#author").textbox('setValue', detail.author);
            $("#pagenumber").textbox('setValue', detail.pagenumber);
            $("#publishdate").textbox('setValue', detail.publishdate);
            $("#pressname").textbox('setValue', detail.press.name);
            $("#authorintroduce").textbox('setValue', detail.authorintroduce);
            $("#bookintroduce").textbox('setValue', detail.bookintroduce);
            $("#file").attr('src', imgurl);
        }

        //工具栏
        var toolbar = [{
            text: '添加',
            iconCls: 'icon-edit',
            handler: function () {
                $("#get_bookname").textbox('setValue', "");
                $("#get_price").textbox('setValue', "");
                $("#get_groupprice").textbox('setValue', "");
                $("#get_author").textbox('setValue', "");
                $("#get_pagenumber").textbox('setValue', "");
                $("#get_publishdate").textbox('setValue', "");
                $("#get_pressname").textbox('setValue', "");
                $("#get_bookintroduce").textbox('setValue', "");
                $('#dd :file').val("");
                $('#get_onlinefile').attr("src", "");
                $('#dd').dialog('open');
            }
        }];
        $(function () {
            $("#booknameKey").val("");
            $("#ISBNKey").val("");
            $('#booklist').datagrid({
                title: '审核列表',
                iconCls: 'icon-save',
                url: '/manager/examine/findAll',
                columns: [
                    [
                        {field: 'title', title: '审核标题', width: 300, align: 'center'},
                        {
                            field: 'info', title: '审核备注', width: 500, align: 'center',
                            formatter: function (value, row, index) {
                                if (value == null) {
                                    return "--";
                                }
                                return value;
                            }
                        },
                        {
                            field: 'flag', title: '审核状态', width: 80, align: 'center',
                            formatter: function (value, row, index) {
                                if (value === 1) {
                                    return "通过";
                                } else if (value === -1) {
                                    return "未通过";
                                }
                                return "审核中";
                            }
                        },
                        {
                            field: '#',
                            title: '书籍详情',
                            width: 200,
                            align: 'center',
                            formatter: function (value, row, index) {
                                return "<a href='#' onclick='showDetails(" + index + ")'>查看</a>";
                            }
                        },

                        {field: 'book', hidden: true},
                        {field: 'number', hidden: true}
                    ]
                ],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            })
            ;

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    $('#booklist').datagrid({
                        queryParams:
                            {
                                "booknameKey": $("#booknameKey").val(),
                                "ISBNKey": $("#ISBNKey").val()
                            }
                    });   //点击搜索
                });

            //初始化添加窗口
            $('#dd').dialog({
                title: '添加书籍',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: "获取",
                    iconCls: 'icon-reload',
                    handler: function () {
                        $.ajax({
                            url: "/manager/book/getonline",
                            data: {
                                "ISBN": $("#get_ISBN").textbox('getValue')
                            },
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                if (data.status !== 2001 && data.status !== 0) {
                                    alert(data.msg);
                                } else {

                                    let book = data.data;
                                    $("#get_bookname").textbox('setValue', book.bookname);
                                    $("#get_price").textbox('setValue', book.price);
                                    $("#get_groupprice").textbox('setValue', book.groupprice);
                                    $("#get_author").textbox('setValue', book.author);
                                    $("#get_pagenumber").textbox('setValue', book.pagenumber);
                                    $("#get_publishdate").textbox('setValue', book.publishdate);
                                    $("#get_pressname").textbox('setValue', book.press.name);
                                    $("#get_bookintroduce").textbox('setValue', book.bookintroduce);
                                    $("#get_onlinefile").attr("src", book.imgurl);
                                    $("#get_onlineimg").val(book.imgurl);

                                }
                            }
                        });
                    }
                }, {
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        let formData = new FormData($("#book")[0]);
                        $.ajax({
                            url: "/manager/book/add",
                            data: formData,
                            type: "post",
                            dataType: "json",
                            processData: false,
                            contentType: false,
                            success: function (data) {
                                if (data.status !== 2001) {
                                    $('#dd').dialog('close');
                                    alert(data.msg);
                                } else {
                                    $('#dd').dialog('close');
                                    $('#booklist').datagrid('reload');
                                }
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog('close');
                    }
                }]
            });
            //初始化查看书籍详情窗口
            $('#detail').dialog({
                title: '书籍详情',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
            });

        })
        ;
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input type="text" id="booknameKey" size=20 placeholder="书籍名称"/>
        <input type="text" id="ISBNKey" size=20 placeholder="ISBN"/>

    </td>
    <td>
        <a id="submit_search">查询</a>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="book" method="post" enctype="multipart/form-data">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookname" id="get_bookname" style="width:50%"
                       data-options="label:'书籍名称:',required:true" readonly>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="ISBN" id="get_ISBN" style="width:50%"
                       data-options="label:'ISBN:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="price" id="get_price" style="width:50%"
                       data-options="label:'单价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="number" id="get_number" style="width:50%"
                       data-options="label:'数量:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="groupprice" id="get_groupprice" style="width:50%"
                       data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="author" id="get_author" style="width:50%"
                       data-options="label:'作者:',required:true" readonly>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="pagenumber" id="get_pagenumber" style="width:50%"
                       data-options="label:'页数:',required:true" readonly>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="publishdate" id="get_publishdate" style="width:50%"
                       data-options="label:'出版日期:',required:true,prompt:'格式(yyyy-MM-dd)'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="pressname" id="get_pressname" style="width:50%"
                       data-options="label:'出版社:',required:true" readonly>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookintroduce" id="get_bookintroduce" style="width:50%;height:60px"
                       data-options="label:'书籍简介:',multiline:true" readonly>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="authorintroduce" id="get_authorintroduce"
                       style="width:50%;height:60px"
                       data-options="label:'作者简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input type="file" name="file" accept="image/jpeg,image/gif" />
            </div>
            <div style="margin-bottom:20px">
                在线图片:&nbsp;&nbsp;&nbsp;&nbsp; <img id="get_onlinefile" src="" style="width:250px" alt="还未获取"/>
                <input id="get_onlineimg" name="onlineimg" type="hidden"/>
            </div>
        </form>
    </div>
</div>
<div id="detail">
    <div align="center" style="margin-top: 30px">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="bookname" style="width:50%"
                   data-options="label:'书籍名称:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="ISBN" style="width:50%"
                   data-options="label:'ISBN:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="price" style="width:50%"
                   data-options="label:'单价:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="number" style="width:50%"
                   data-options="label:'待上架数量:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="groupprice" style="width:50%"
                   data-options="label:'团购价:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="author" style="width:50%"
                   data-options="label:'作者:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="pagenumber" style="width:50%" data-options="label:'页数:',required:true"
                   readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="publishdate" style="width:50%"
                   data-options="label:'出版日期:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="pressname" style="width:50%" data-options="label:'出版社:',required:true"
                   readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="bookintroduce" style="width:50%;height:60px"
                   data-options="label:'书籍简介:',multiline:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="authorintroduce" style="width:50%;height:60px"
                   data-options="label:'作者简介:',multiline:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <img id="file" src="" style="width:250px" alt="封面"/>
        </div>
    </div>
</div>
</body>
</html>